<?php

require_once(TEST_INTEGRATION_PATH . 'Orders.php');

class TestOfOrdersFind extends UnitTestCase {	
	private $order;
	private $db;
	
	function __construct() {
		$this->order = new Orders;
		$this->db = new Datasource(TEST_DB_SERVER, TEST_DB_DATABASE, TEST_DB_SERVER_USERNAME, TEST_DB_SERVER_PASSWORD);
	}
	
	function setUp() {
		$this->db->execute("INSERT INTO orders (orders_id ,customers_id ,customers_name ,customers_company ,customers_street_address ,customers_suburb ,customers_city ,customers_postcode ,customers_state ,customers_country ,customers_telephone ,customers_email_address ,customers_address_format_id ,delivery_name ,delivery_company ,delivery_street_address ,delivery_suburb ,delivery_city ,delivery_postcode ,delivery_state ,delivery_country ,delivery_address_format_id ,billing_name ,billing_company ,billing_street_address ,billing_suburb ,billing_city ,billing_postcode ,billing_state ,billing_country ,billing_address_format_id ,payment_method ,payment_module_code ,shipping_method ,shipping_module_code ,coupon_code ,cc_type ,cc_owner ,cc_number ,cc_expires ,last_modified ,date_purchased ,orders_status ,orders_date_finished ,currency ,currency_value ,order_total ,order_tax ,paypal_ipn_id ,ip_address) VALUES ('1', '1', 'Bill Smith', 'JustaDemo', '123 Any Avenue', '', 'LA', '12345', 'California', 'United States', '12345', 'root@localhost', '2', 'Bill Smith', 'JustaDemo', '123 Any Avenue', '', 'LA', '12345', 'California', 'United States', '2', 'Bill Smith', 'JustaDemo', '123 Any Avenue', '', 'LA', '12345', 'California', 'United States', '2', 'Cash on Delivery', 'cod', 'Store Pickup (Walk In)', 'storepickup', '', '', '', '', '', NULL , '2008-01-30 16:15:56', '3', NULL , 'USD', '1.000000', '299.99', '0.00', '0', '127.0.0.1 - 127.0.0.1' )");
		$this->db->execute("INSERT INTO orders_products VALUES ('1', '1', '1', 'MG200MMS', 'Matrox G200 MMS', '299.9900', '299.9900', '0.0000', '1', '0.0000', '0', '0', '0', '0', '1:edff669e5da95c1d027b04d5412532fa')");		
	}
	
	function tearDown() {
		$this->db->execute("DELETE FROM `orders` WHERE `orders_id` = 1");
		$this->db->execute("DELETE FROM `orders_products` WHERE `orders_products_id` = 1");
	}

	function testShouldListOrders() {
		
		$product = new ProductDTO;
		$product->pid = 1;
		
		$order = new OrderDTO;
		$order->currency = "USD";
		$order->date = "2008-01-30 16:15:56";
		$order->method = "Cash on Delivery";
    	$order->oid = "1";
		$order->price = "299.99";
		$order->pids = array($product);
		
		$dtoArray = array();
		array_push($dtoArray, $order);
		
		$test = $this->order->find(0);
		$this->assertEqual($test, $dtoArray);
	}
}

?>
